<template>
    <div class="sidebar">
        <el-menu :default-active="onRoutes" class="el-menu-vertical-demo el-menu--dark" theme="dark" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index">
                        <template slot="title"><i :class="item.icon"></i>{{ item.title }}</template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">{{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index">
                        <i :class="item.icon"></i>{{ item.title }}
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                items: [
                    {
                        icon: 'el-icon-star-off',
                        index: '4',
                        title: '前台',
                        subs: [
                            {
                                index: '/banner',
                                title: '轮播图'
                            },
                            {
                                index: '/dynamic',
                                title: '动态'
                            },
                            {
                                index: '/help',
                                title: '帮助中心'
                            },
                            {
                                index: '/service',
                                title: '服务'
                            },
                            {
                                index: '/coupon',
                                title: '优惠券'
                            },
                            {
                                index: '/redeemCode',
                                title: '兑换码'
                            },
                            {
                                index: '/redeemRecord',
                                title: '兑换记录'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-menu',
                        index: '5',
                        title: '后台',
                        subs: [
                            {
                                index: '/school',
                                title: '学校'
                            },
                            {
                                index: '/student',
                                title: '学生'
                            },
                            {
                                index: '/num',
                                title: '号码牌'
                            },
                            {
                                index: '/fans',
                                title: '用户'
                            },
                            {
                                index: '/config',
                                title: '配置'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-document',
                        index: '6',
                        title: '订单',
                        subs: [
                            {
                                index: '/order',
                                title: '订单'
                            },
                            {
                                index: '/refund',
                                title: '退款'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-setting',
                        index: '7',
                        title: '权限',
                        subs: [
                            {
                                index: '/permission',
                                title: '权限'
                            },
                            {
                                index: '/role',
                                title: '角色'
                            },
                            {
                                index: '/role/attach',
                                title: '权限分配'
                            },
                            {
                                index: '/role/sync',
                                title: '角色分配'
                            },
                            {
                                index: '/user',
                                title: '管理员'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-warning',
                        index: '9',
                        title: '关于微信',
                        subs: [
                            {
                                index: '/key',
                                title: '关键字'
                            },
                            {
                                index: '/wx/send',
                                title: '微信信息发送'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-date',
                        index: '8',
                        title: '数据图表',
                        subs: [
                            {
                                index: '/wxdata',
                                title: '微信数据显示'
                            },
                            {
                                index: '/lexisummary',
                                title: '用户统计数据'
                            },
                            {
                                index: '/realtime',
                                title: '实时数据显示'
                            },
                            {
                                index: '/schoolsummary',
                                title: '学校统计数据'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-plus',
                        index: '/add',
                        title: '添加'
                    }
                ]
            }
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
        }
    }
</script>

<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        width: 250px;
        left: 0;
        top: 70px;
        bottom:0;
        background: #2E363F;
    }
    .sidebar > ul {
        height:100%;
    }
    .el-menu--dark{
        background-color: #324157;
    }
</style>
